﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TestDemo</title>
</head>
<body>
    <div class="c-file" id="container">
        <label for="f1" class="btn btn-green" id="pickfiles">选择文件</label>
        <label id="fileName"></label>
    </div>
    <button type="button" id="upload">上传</button>
    <input type="hidden" id="domain" value="http://o8wd2ksiq.bkt.clouddn.com/">
    <input type="hidden" id="FileURL" value="" />
    <script src="~/Content/vendor/jquery/jquery.min.js"></script>
    <script src="~/Content/qiniu/plupload-2.1.8/js/plupload.full.min.js"></script>
    <script src="~/Content/qiniu/plupload-2.1.8/js/i18n/zh_CN.js"></script>
    <script src="~/Content/qiniu/qiniu.min.js"></script>
    <script type="text/javascript">
        var qiniu1 = QiniuInit();

        $('#upload').click(function () {
            qiniu1.start();
        });

        function QiniuInit() {
            var obj2 = Qiniu.uploader({
                runtimes: 'html5,flash,html4',
                browse_button: 'pickfiles',
                container: 'container',
                drop_element: 'container',
                max_file_size: '1000mb',
                flash_swf_url: '/Content/qiniu/plupload-2.1.8/js/Moxie.swf',
                dragdrop: false,
                chunk_size: '100mb',
                multi_selection: !(mOxie.Env.OS.toLowerCase() === "ios"),
                uptoken_url: '/QINIU/GetUploadToken',
                domain: $('#domain').val(),
                get_new_uptoken: false,
                unique_names: true,
                auto_start: false,
                multi_selection: false,
                log_level: 5,
                init: {
                    'FilesAdded': function (up, files) {
                        var fileNames = $('#fileName');

                        fileNames.html('');

                        var flength = up.files.length - files.length;
                        for (var i = 0; i < flength; i++) {
                            up.removeFile(up.files[0]);
                        }

                        plupload.each(up.files, function (file) {
                            var tfile = file.name.substring(file.name.lastIndexOf('.'));
                            if ('.jpg.png'.indexOf(tfile) == -1) {
                                alert('选择文件格式不对，只能上传 ' + fileType[index] + ' 格式的文件，请重新选择！');
                                return false;
                            }
                        });

                    },
                    'BeforeUpload': function (up, file) {

                    },
                    'UploadProgress': function (up, file) {

                    },
                    'UploadComplete': function () {

                    },
                    'FileUploaded': function (up, file, info) {
                        info = JSON.parse(info);
                        var url = $('#FileURL');
                        url.val(url.val() + ',' + $('#domain').val() + info.key);
                        alert('OK');
                        // 上传成功后

                    },
                    'Error': function (up, err, errTip) {
                    }
                }
            });
            return obj2;
        }

    </script>
</body>
</html>
